package mx.com.daycare.managed;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.model.DualListModel;

import mx.com.daycare.business.CourseBLLocal;
import mx.com.daycare.business.TeacherBLLocal;
import mx.com.daycare.entity.Course;
import mx.com.daycare.entity.Teacher;

@ManagedBean
@ViewScoped
public class TeacherMB {

	private Teacher teacher;
	private List<Teacher> teachers;
	private List<Teacher> teachersFiltered;
	private DualListModel<Course> courses;
	private List<Course> coursesSource;
	private List<Course> coursesTarget;

	@EJB
	private TeacherBLLocal teacherBL;

	@EJB
	private CourseBLLocal courseBL;

	@PostConstruct
	public void init() {
		teachers = teacherBL.getTeachers();
		coursesSource = new ArrayList<Course>();
		coursesTarget = new ArrayList<Course>();
		courses = new DualListModel<Course>(coursesSource, coursesTarget);
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public List<Teacher> getTeachers() {
		return teachers;
	}

	public void setTeachers(List<Teacher> teachers) {
		this.teachers = teachers;
	}

	public List<Teacher> getTeachersFiltered() {
		return teachersFiltered;
	}

	public void setTeachersFiltered(List<Teacher> teachersFiltered) {
		this.teachersFiltered = teachersFiltered;
	}

	public String initDialog() {
		teacher = new Teacher();
		coursesSource = courseBL.getCourses();		
		courses.setSource(coursesSource);
		return null;
	}

	public DualListModel<Course> getCourses() {
		return courses;
	}

	public void setCourses(DualListModel<Course> courses) {
		this.courses = courses;
	}
}
